home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / hard / hack / ibm_keyboard.lha / key.asm < prev    next >
Assembly Source File  |  1992-03-25  |  32KB  |  1,024 lines

  1. ;* these port equates are explained below. Relocate them to any of
  2. ;* Port1, pins 0-7 or Port3, pins 0-7, except Port3, pins2 and 3
  3. ;* because these are the external interrupts.
  4. ;* it doesn't matter as long as you equate the right pin to the right
  5. ;* signal.
  6.  
  7.         .equ    Kclk,p1.0
  8.         .equ    Kdat,p1.1
  9.         .equ    Aclk,p1.3
  10.         .equ    Adat,p1.4
  11.         .equ    Areset,p1.5
  12.         .equ    Kswitch,p1.7
  13.  
  14.         .org    0000h
  15. init:   ljmp    start
  16.         .org    0003h
  17.         ljmp    resetint
  18.         .org    001bh
  19.         ljmp    timer1int
  20.  
  21. ;**************************************************
  22. ;*
  23. ;*
  24. ;* Equates Descriptions:
  25. ;* 
  26. ;*      Aclk is the line to the Amiga keyboard clock in. (P1.3)
  27. ;*      Adat is the line to the Amiga keyboard data in. (P1.4)
  28. ;*      Areset is the Amiga Reset line (P1.5) (for the A500)
  29. ;*      Kclk is the line to the Keyboard clock out (P1.0)
  30. ;*      Kdat is the line to the Keyboard data out (P1.1)
  31. ;*      Kstyle is bit defining whether or not the keyboard
  32. ;*        is AT or XT. if AT, Kstyle=1
  33. ;*
  34. ;*      Oldchar is the last character typed to go to the Amiga.
  35. ;* This is used to tell if the Capslock was Pressed and 
  36. ;* Released without pressing any other keys. If this was done, 
  37. ;* then it is a "Caps Lock" otherwise, the Caps key functions
  38. ;* as the Control Key because of the keyboard remapping.
  39. ;*
  40. ;*      Capbit is the flag which tells whether the Caps Lock
  41. ;* should be down or up.
  42. ;*      Capdown is the flag which tells whether the Caps Lock 
  43. ;* KEY is presently down or up. The difference between Capdown 
  44. ;* and Capbit is that Capdown relates to the KEY. Capbit toggles 
  45. ;* once for every "press and release" of the Cap Lock Key. 
  46. ;* Press and release Cap Lock Key, and Capbit goes low.....
  47. ;* Press and release it again, and Capbit goes high....
  48. ;*      Cntldown is the flag which is set and reset when you 
  49. ;* press Cap Lock and then another key. Then, Cap Lock Key 
  50. ;* functions as the Control Key.
  51. ;* LAMIGA,RAMIGA,and CONTROL are all flags that tell if those 
  52. ;* keys are being held down. When all three are, the computer
  53. ;* will reset.
  54. ;*
  55. ;* ATparity is the 10th bit that the AT keyboard transmits. It 
  56. ;* is SET if the number of DATA bits set is EVEN. Otherwise, its
  57. ;* CLEARED.
  58. ;*
  59. ;**************************************************
  60.  
  61.         ;bit memory locations:
  62.  
  63.         .equ    Capbit,42h
  64.         .equ    Capdown,43h
  65.         .equ    Ctrldown,44h
  66.         .equ    CONTROL,45h
  67.         .equ    LAMIGA,46h
  68.         .equ    RAMIGA,47h
  69.         .equ    ATparity,48h
  70.         .equ    Make,49h
  71.         .equ    XT7bit,4ah
  72.         .equ    Kstyle,4bh
  73.  
  74.         ;byte memory locations:
  75.  
  76.         .equ    Charbad,50h
  77.         .equ    Oldchar,51h
  78.         .equ    Amigachar,52h
  79.  
  80.         .org    0200h
  81.  
  82. start:  mov     tmod,#11h       ;two 16 bit timers
  83.         mov     tcon,#05h    ;edge triggered interrupt.
  84.         mov     ie,#00h         ;clear all interrupts
  85.         setb    ea
  86.         setb    et1             ;enable timer 1
  87.         setb    ex0             ;enable external 0
  88.         setb    int0            ;make sure it's high
  89.         setb    pt0        ;timer 0 has high priority
  90.         mov     sp,#30h         ;stack somewhere safe.
  91.  
  92. ; set the ports for input
  93.         mov     p1,#255         ;set port1 for read
  94.         clr     tr1             ;make sure timers are in
  95.         clr     tf1             ;reset state.
  96.         clr     tr0
  97.         clr     tf0
  98.  
  99. ; clear out the miscellaneous flags.
  100.         clr     Capdown         ;Caps is up...
  101.         clr     Ctrldown        ;Control is up
  102.         clr     Capbit          ;Caps light is off.
  103.         setb    CONTROL         ;all reset keys are UP
  104.         setb    LAMIGA
  105.         setb    RAMIGA
  106.  
  107. ;**** sync the controller with the Amiga. clock out
  108. ;**** ones until we receive a handshake...
  109. sync:
  110.         mov     tl1,#0          ;set up timer for 143ms
  111.         mov     th1,#0
  112.         mov     r1,#2
  113.         setb     tr1
  114. sync2:
  115.         jb      Adat,sync2      ;wait for handshake
  116. sync3:
  117.         jnb     Adat,sync3      ;wait for end of handshake
  118.         clr     tr1
  119.  
  120. ;**** transmit power up key stream and end key stream.
  121.         mov     a,#0FDh
  122.         acall   actualtransmit
  123.         mov     a,#0FEh
  124.         acall   actualtransmit
  125.  
  126. ;**** test for XT keyboard, if Kswitch is low, automatically
  127. ;**** jump to XT mode.
  128. ;**** otherwise, test to see if Kdat is low and stays there.
  129. ;**** If so, it's in XT mode.                                
  130.  
  131.         jnb     Kswitch,XTPowerup 
  132.         jb      Kdat,ATPowerup
  133.         mov     th0,#0
  134.         mov     tl0,#0
  135.         clr     tf0
  136.         setb    tr0
  137. XTtest: jb      tf0,XTPowerup   ;timer ran out. XT mode.
  138.         jnb     Kdat,XTtest     ;data is low, but for how long?
  139.         clr     tr0
  140.         clr     tf0
  141.         sjmp    ATPowerup
  142. XTPowerup:
  143.         clr     Kstyle          ;XT flag.
  144.         clr     tf0
  145.         clr     Kclk            ;Clock low=Reset for the XT.
  146. XTreset:
  147.         jnb     tf0,XTreset
  148.         setb    Kclk
  149.         clr     tr0
  150.         clr     tf0
  151. ll:     acall   XTgetkey        ;(Should be AA)
  152.         ljmp    XTstyle
  153.  
  154. ;**** sync up the AT and go with it!
  155.  
  156. ATPowerup:
  157.         setb    Kstyle
  158.         mov     a,#0ffh         ;RESET
  159.         acall   SendtoAT
  160.         mov     a,#0f6h         ;DEFAULT
  161.         acall   SendtoAT
  162.         mov     a,#0edh         ;NEXT DATA is FOR LIGHTS
  163.         acall   SendtoAT
  164.         mov     a,#2            ;NUMLOCK ON?
  165.         acall   SendtoAT
  166.         mov     a,#0f4h         ;CLEAR BUFFER
  167.         acall   SendtoAT
  168.         ljmp    ATstyle         ;go and parse AT keyboard
  169.  
  170. ;***********************************************
  171. ;* ATgetkey
  172. ;* ATgetkey
  173. ;* ATgetkey
  174. ;*
  175. ;* ATgetkey looks at the keyboard and waits for a key to be
  176. ;* pressed. ATinkey is the actual routine that watched the logic
  177. ;* levels of Kdat and Kclk. IF the character's parity is not 
  178. ;* what it is supposed to be, then the routine will attempt to
  179. ;* tell the keyboard to resend.
  180. ;*
  181. ;* When exiting from this routine, Kclock is pulled low to hold 
  182. ;* off any more transmissions. You must restore it to 5 volts to
  183. ;* receive any more characters later.
  184. ;*
  185. ;*
  186.  
  187. ATgetkey:
  188.         mov     r0,#11          ;number of bits
  189.         setb    Kclk
  190. ATwaitC0:         
  191.         jb      Kclk,ATwaitC0   ;wait for a clock pulse
  192.         dec     r0              ;decrement clock bit counter
  193.         cjne    r0,#10,ATnstart ;test for startbit
  194.         sjmp    ATwait  
  195. ATnstart:
  196.         cjne    r0,#0,ATnstop   ;check for stopbit      
  197. ATwaitC1:
  198.         jnb     Kclk,ATwaitC1   ;wait for clock to go high                     
  199.         clr     Kclk            ;hold off more data
  200.         mov     r0,#20          ;small delay
  201. pause:  djnz    r0,pause
  202. ;**** now we check to see if the parity between
  203. ;**** Bit register P (which is set if Parity of Acc is odd)
  204. ;**** is compared to the received Parity Bit.
  205.         jb      p,parityodd     ;test if parity of DATA is odd
  206. parityeven:
  207.         jnb     ATparity,ATerror
  208.         ret                     ;Okay to return. A=valid
  209. parityodd:
  210.         jb      ATparity,ATerror
  211.         ret                     ;Okay to return. A=valid
  212. ATerror:
  213.         mov     a,#0feh         ;RESEND character
  214.         acall   SendtoAT
  215.         sjmp    ATgetkey        ;now return to caller
  216. ATnstop:
  217.         cjne    r0,#1,ATdatab   ;check for paritybit
  218.         mov     c,Kdat          ;error checking! (AT only)
  219.         mov     ATparity,c
  220.         sjmp    ATwait          ;
  221. ATdatab: 
  222.         mov     c,Kdat          ;get data bit
  223.         rrc     a               ;shift it into accumulator
  224. ATwait: jnb     Kclk,ATwait     ;wait for clock line to go low
  225.         sjmp    ATwaitC0        ;get another bit
  226.  
  227.  
  228. ;**************************************************
  229. ;* AT-STYLE
  230. ;*
  231. ;*     This waits for a keycode or two from the IBM and then calls
  232. ;* the appropriate transmit subroutine. The IBM keyboard sends 
  233. ;* out special codes in front of and behind some scancodes. This
  234. ;* routine will chop them out before doing a lookup on the 
  235. ;* code to see what to send to the AMIGA. The scancodes between 
  236. ;* the IBM and the AMIGA are of course, not the same!
  237. ;*
  238. ;**************************************************
  239.  
  240. ATstyle:
  241.         acall   ATgetkey          ;get one scancode.
  242.         cjne    a,#0e1h,ATnE1
  243.         acall   ATgetkey          ;(should be 14)
  244.         acall   ATgetkey          ;(should be 77)
  245.         acall   ATgetkey          ;(should be E1)
  246.         acall   ATgetkey          ;(should be F0)
  247.         acall   ATgetkey          ;(should be 14)
  248.         acall   ATgetkey          ;(should be F0)
  249.         acall   ATgetkey          ;(should be 77)
  250.         sjmp    ATstyle
  251. ;PAUSE was pressed. Just ignore it.
  252. ATnE1:
  253.         mov     dptr,#ATtb1
  254.         cjne    a,#0e0h,ATnE0
  255.         mov     dptr,#ATtb2
  256.         acall   ATgetkey
  257.         cjne    a,#0f0h,ATnE0F0
  258.         acall   ATgetkey
  259.         cjne    a,#12h,ATnEF12
  260.         ljmp    ATstyle         ;(E0F012....ignore it)
  261. ATnEF12:
  262.         cjne    a,#59h,ATup     ;(E0F0mk)
  263.         ljmp    ATstyle         ;(E0F059....ignore it)
  264. ATnE0F0:
  265.         cjne    a,#12h,ATnE012
  266.         ljmp    ATstyle         ;(E012....ignore it)
  267. ATnE012:
  268.         cjne    a,#59h,ATdown   ;(E0mk)
  269.         ljmp    ATstyle         ;(E059....ignore it)
  270. ATnE0:
  271.         cjne    a,#0f0h,ATdown  ;(mk)
  272.         acall   ATgetkey
  273.         sjmp    ATup            ;(F0mk....normal key break)
  274.  
  275. ;**************************************************
  276. ;* ATdown and the rest here call a lookup table to change
  277. ;* the AT scancodes into AMIGA scancodes. In the "down"
  278. ;* routine, the "make" bit is asserted. In the "up" routine
  279. ;* it is de-asserted.
  280. ;**************************************************
  281. ATdown:
  282.         movc    a,@a+dptr       ;indexed into table
  283.         clr     acc.7           ;clear make/break bit
  284.         acall   transmit        ;transmit it
  285.         ljmp    ATstyle
  286. ATup:
  287.         movc    a,@a+dptr
  288.         setb    acc.7           ;set make/break bit
  289.         acall   transmit        ;transmit it
  290.         ljmp    ATstyle
  291.  
  292. ;**************************************************
  293. ;* SendtoAT is the subroutine that sends special codes
  294. ;* to the keyboard from the controller. Codes include
  295. ;* the command to reset (FF) or the command to change
  296. ;* the lights (ED). It is advisable to keep the timing
  297. ;* very close to how I have it done in this routine.
  298. ;**************************************************
  299.  
  300. SendtoAT:
  301.         setb    Kclk
  302.         clr     Kdat
  303.         mov     r0,#8
  304. Send4:  jb      Kclk,Send4      ;data bit
  305.         mov     c,acc.0
  306.         mov     Kdat,c
  307.         rr      a 
  308. Send5:  jnb     Kclk,Send5      ;data bit
  309.         dec     r0
  310.         cjne    r0,#0,Send4
  311.         mov     c,p
  312.         cpl     c
  313. Send6:  jb      Kclk,Send6      ;parity bit
  314.         mov     Kdat,c
  315. Send7:  jnb     Kclk,Send7      ;parity bit
  316. Send77: jb      Kclk,Send77     ;stop bit
  317.         setb    Kdat
  318. Send78: jnb     Kclk,Send78     ;stop bit
  319. Send79: jb      Kclk,Send79
  320. Send7a: jnb     Kclk,Send7a
  321.         mov     r0,#8           ;small delay
  322. Send8:  djnz    r0,Send8
  323.         clr     Kclk            ;drive clock low
  324.         mov     r0,#20          ;long delay
  325. Send9:  djnz    r0,Send9
  326.         setb    Kclk
  327.         acall   ATgetkey        ;should check if response isbad.
  328.         ret                     ;who cares if it is? not me!
  329.  
  330. XTgetkey:
  331.         setb    Kdat            ;let data flow!
  332.         mov     r0,#8
  333. XTw1:   jb      Kclk,XTw1       ;start bit1
  334. XTw2:   jnb     Kclk,XTw2       ;start bit1
  335. XTw3:   jb      Kclk,XTw3       ;start bit2
  336. XTw4:   jnb     Kclk,XTw4       ;start bit2
  337. XTw5:   jb      Kclk,XTw5       ;data bit
  338.         mov     c,Kdat
  339.         rrc     a
  340. XTw6:   jnb     Kclk,XTw6       ;data bit
  341.         djnz    r0,XTw5
  342.         clr     Kdat            ;hold off data
  343.         ret
  344.  
  345. XTstyle:
  346.         acall   XTgetkey
  347.         cjne    a,#0e1h,XTnE1
  348.         acall   XTgetkey        ;(should be 1d)
  349.         acall   XTgetkey        ;(should be 45)
  350.         acall   XTgetkey        ;(should be e1)
  351.         acall   XTgetkey        ;(should be 9d)
  352.         acall   XTgetkey        ;(should be c5)
  353.         sjmp    XTstyle
  354. XTnE1:
  355.         cjne    a,#0e0h,XTnE0
  356.         acall   XTgetkey
  357.         cjne    a,#0aah,XTnAA
  358.         sjmp    XTstyle
  359. XTnAA:
  360.         cjne    a,#2ah,XTn2A
  361.         sjmp    XTstyle
  362. XTn2A:
  363.         cjne    a,#0b6h,XTnB6
  364.         sjmp    XTstyle
  365. XTnB6:
  366.         cjne    a,#36h,XTn36
  367.         sjmp    XTstyle
  368. XTn36:
  369.         mov     dptr,#XTtb2
  370. XTlookup:
  371.         mov     c,acc.7         ;(1=break)
  372.         mov     XT7bit,c
  373.         clr     acc.7
  374.         movc    a,@a+dptr
  375.         mov     c,XT7bit
  376.         mov     acc.7,c
  377.         acall   transmit
  378.         ljmp    XTstyle
  379. XTnE0:
  380.         mov     dptr,#XTtb1
  381.         sjmp    XTlookup
  382.  
  383. ;**************************************************
  384. ;*
  385. ;* TRANSMIT first does some checking to take out repeating
  386. ;* keys and does the conversion on the Caps Lock Key and
  387. ;* then calls Actualtransmit.
  388. ;*
  389. ;**************************************************
  390.  
  391. dontrans:                       ;jumps back if key is already
  392.         pop     acc             ;held down.
  393.         ret
  394. transmit:
  395.         cjne    a,Oldchar,transok
  396.         ret
  397. transok:
  398.         cjne    a,#62h,transok2 ;jump if not CapsLock=down
  399.         mov     Oldchar,a
  400.         setb    Capdown         ;set the flags for later
  401.         ret
  402. transok2:                       
  403.         cjne    a,#0e2h,transok3;jump if not CapsLock=up
  404.         mov     a,Oldchar       ;see if Caps was just down
  405.         jnb     Kstyle,XTcap    ;if XT, skip control feature.
  406.         cjne    a,#62h,transok4 ;if not, then it was a control
  407. XTcap:
  408.         clr     Capdown         ;clear flag
  409.         cpl     Capbit          ;toggle down/up-ness of Caplock
  410.         mov     a,#62h
  411.         mov     c,Capbit
  412.         cpl     c
  413.         mov     acc.7,c
  414.         acall   actualtransmit  ;(Caps to Amiga!)
  415.         jnb     Kstyle,skiplights ;(don't do lights if XT)
  416.         mov     a,#0edh         ;set lights on next byte.
  417.         acall   SendtoAT
  418.         mov     a,#2            ;numlock on
  419.         mov     c,Capbit
  420.         mov     acc.2,c
  421.         acall   SendtoAT        ;maybe capslock light
  422. skiplights: 
  423.         ret           
  424. transok4:
  425.         clr     CtrlDown        ;This sends out a Control Up.
  426.         clr     Capdown         ;Caps lock is done functioning as Ctl
  427.         mov     a,#63h          ;Control Key
  428.         setb    acc.7           ;break bit set.
  429.         acall   actualtransmit  ;send to Amiga.
  430.         ret
  431. transok3:
  432.         mov     Oldchar,a
  433.         jnb     Kstyle,noControl
  434.         jnb     Capdown,noControl
  435.         jb      CtrlDown,noControl
  436.         setb    CtrlDown        ;Caps lock is beginning to function
  437.         mov     a,#63h          ;as the Control Key.
  438.         acall   actualtransmit  ;send Control Down to Amiga
  439.         mov     a,Oldchar       ;now send the actual key
  440.  
  441. noControl:                      ;its not a controlled key
  442.         mov     c,acc.7         ;c=make/break bit
  443.         mov     Make,c          ;will be set if key up
  444.         clr     acc.7           ;test for key only. NO make/break
  445.         cjne    a,#0eh,noMup    ;special key mouse up
  446.         jnb     Make,kmupdown
  447. kmupup:
  448.         mov     a,#0cch         ;cursor up break
  449.         acall   actualtransmit
  450.         acall   Smalldelay
  451.         mov     a,#0e7h         ;right amiga break
  452.         acall   actualtransmit
  453.         ret
  454. kmupdown:
  455.         mov     a,#67h          ;amiga make
  456.         acall   actualtransmit
  457.         acall   Smalldelay
  458.         mov     a,#4ch          ;cursor up make
  459.         acall   actualtransmit
  460.         ret
  461. noMup:
  462.         cjne    a,#1ch,noMdown  ;special key mouse down
  463.         jnb     Make,kmdowndown
  464. kmdownup:
  465.         mov     a,#0cdh         ;cursor down break
  466.         acall   actualtransmit
  467.         mov     a,#0e7h         ;amiga break
  468.         acall   Smalldelay
  469.         acall   actualtransmit
  470.         ret
  471. kmdowndown:
  472.         mov     a,#67h          ;amiga make
  473.         acall   actualtransmit
  474.         acall   Smalldelay      ;cursor down make
  475.         mov     a,#4dh
  476.         acall   actualtransmit
  477.         ret
  478. noMdown:
  479.         cjne    a,#2ch,noMleft  ;special key mouse left
  480.         jnb     Make,kmleftdown
  481. kmleftup:
  482.         mov     a,#0cfh         ;cursor left break
  483.         acall   actualtransmit
  484.         acall   Smalldelay      ;amiga break
  485.         mov     a,#0e7h
  486.         acall   actualtransmit
  487.         ret
  488. kmleftdown:
  489.         mov     a,#67h          ;amiga make
  490.         acall   actualtransmit
  491.         acall   Smalldelay
  492.         mov     a,#4fh          ;cursor left make
  493.         acall   actualtransmit
  494.         ret
  495. noMleft:                        ;special key mouse right
  496.         cjne    a,#47h,notspecial
  497.         jnb     Make,kmrhtdown
  498. kmrhtup:
  499.         mov     a,#0ceh         ;cursor right break
  500.         acall   actualtransmit
  501.         acall   Smalldelay
  502.         mov     a,#0e7h         ;amiga break
  503.         acall   actualtransmit
  504.         ret
  505. kmrhtdown:
  506.         mov     a,#67h          ;amiga make
  507.         acall   actualtransmit
  508.         acall   Smalldelay
  509.         mov     a,#04eh         ;cursor right make
  510.         acall   actualtransmit
  511.         ret
  512. Smalldelay:
  513.         mov     th0,#0
  514.         mov     tl0,#0
  515.         clr     tf0
  516.         setb    tr0
  517. small1: jnb     tf0,small1
  518.         clr     tf0
  519.         clr     tr0
  520.         ret
  521. notspecial:
  522.         mov     a,Oldchar
  523.         acall   actualtransmit  ;transmit the keycode
  524.         mov     a,Oldchar       ;get back same keycode, in A.
  525.         mov     c,acc.7         ;put make/break bit in Make
  526.         mov     Make,c
  527.         clr     acc.7           ;start testing for reset keys
  528.         cjne    a,#63h,nrset1   ;held down
  529.         mov     c,Make
  530.         mov     CONTROL,c
  531.         sjmp    trset
  532. nrset1: cjne    a,#66h,nrset2
  533.         mov     c,Make
  534.         mov     LAMIGA,c
  535.         sjmp    trset
  536. nrset2: cjne    a,#67h,trset
  537.         mov     c,Make
  538.         mov     RAMIGA,c
  539. trset:  jnb     CONTROL,maybefree       ;if bit set, this key is up
  540.         jb      CtrlDown,maybefree      ;if bit set, this key is down
  541.         sjmp    free
  542. maybefree:
  543.         jb      LAMIGA,free     ;ditto
  544.         jb      RAMIGA,free     ;ditto
  545.         sjmp    resetwarn       ;OOPS! They are all down!
  546. free:   ret
  547. dummy:
  548.         reti
  549. resetint:
  550.         acall   dummy
  551. resetwarn:
  552.         clr     tf0             
  553.         mov     a,78h
  554.         mov     r1,#2           ;set up timer 0 watchdog
  555.         mov     tl0,#0
  556.         mov     th0,#0
  557.         cpl     a               ;invert, don't know why.
  558.         mov     r0,#8
  559. wr1:
  560.         rl      a
  561.         mov     c,acc.7
  562.         mov     Adat,c
  563.         mov     b,#8
  564. wr2:
  565.         djnz    b,wr2             ; transmit it.
  566.         clr     Aclk
  567.         mov     b,#8
  568. wr3:
  569.         djnz    b,wr3
  570.         setb    Aclk
  571.         mov     b,#10
  572. wr4:
  573.         djnz    b,wr4
  574.         djnz    r0,wr1
  575.         setb    Adat
  576.         setb    tr0             ;start watchdog
  577. wr5:
  578.         jnb     Adat,caught1
  579.         jnb     tf0,wr5
  580.         clr     tf0
  581.         djnz    r1,wr5
  582.         sjmp    Hardreset
  583. caught1:
  584.         clr     tr0
  585.         clr     tf0
  586.         mov     a,78h
  587.         mov     r1,#4
  588.         mov     tl0,#0
  589.         mov     th0,#0
  590.         cpl     a    
  591.         mov     r0,#8
  592. wr11:
  593.         rl      a
  594.         mov     c,acc.7
  595.         mov     Adat,c
  596.         mov     b,#8
  597. wr22:
  598.         djnz    b,wr22   
  599.         clr     Aclk
  600.         mov     b,#8
  601. wr33:
  602.         djnz    b,wr33
  603.         setb    Aclk
  604.         mov     b,#10
  605. wr44:
  606.         djnz    b,wr44
  607.         djnz    r0,wr11
  608.         setb    Adat
  609.         setb    tr0             ;start watchdog
  610. wr55:
  611.         jnb     Adat,caught2
  612.         jnb     tf0,wr55
  613.         clr     tf0
  614.         djnz    r1,wr55
  615.         sjmp    Hardreset
  616. caught2:
  617. hold:   jnb     Adat,hold
  618. Hardreset:
  619.         clr     tr0
  620.         clr     tf0
  621.         clr     Areset
  622.         clr     Aclk            ;clear both lines for A500/A1000
  623.         mov     r1,#15          ;clock should go low for over 500ms
  624.         mov     th0,#0          ;timer 1 will overflow repeatedly
  625.         mov     tl0,#0
  626.         setb    tr0
  627. hsloop:
  628.         jnb     tf0,hsloop      ;wait for overflow flag
  629.         clr     tf0             ;clear it again
  630.         djnz    r1,hsloop
  631.         clr     tf0
  632.         clr     tr0             ;stop the timer
  633.         ljmp    start
  634.  
  635. ;**************************************************
  636. ;* 
  637. ;* ActualTransmit sends the character out to the Amiga and waits
  638. ;* for an acknowledge handshake. If it does not receive one in
  639. ;* 143 ms, then it clocks out 1's on the data line until it 
  640. ;* receives the acknowledge. If the Amiga is not connected up, 
  641. ;* then it will hang here. The handshake is that the AMIGA 
  642. ;* drives the clock line low.
  643. ;*
  644. ;*      The loops with register B are for timing delays. 
  645. ;* There should be about 20usec between when the Data line is 
  646. ;* set, the Clock line is driven low, and the Clock line
  647. ;* is driven high.
  648. ;*
  649. ;**************************************************
  650.  
  651. actualtransmit:
  652.         mov     Amigachar,a     ;set the character to transmit
  653.  
  654.         mov     r0,#05          ;do a small delay
  655. dly:
  656.         mov     b,#0
  657. delay:  djnz    b,delay
  658.         djnz    r0,dly
  659.  
  660. actual2:
  661.         mov     a,Amigachar     ;restore it
  662.         clr     Charbad         ;character is not bad yet
  663.         mov     r1,#2           ;set up timer 0 watchdog
  664.         mov     tl1,#0
  665.         mov     th1,#0
  666.         cpl     a               ;invert, don't know why.
  667.         mov     r0,#8
  668. f:      rl      a
  669.         mov     c,acc.7
  670.         mov     Adat,c
  671.         mov     b,#8
  672. g:      djnz    b,g             ; transmit it.
  673.         clr     Aclk
  674.         mov     b,#8
  675. h:      djnz    b,h
  676.         setb    Aclk
  677.         mov     b,#10
  678. i:      djnz    b,i
  679.         djnz    r0,f
  680.         setb    Adat
  681.         setb    tr1             ;start watchdog
  682. waitshake:
  683.         jb      Adat,waitshake
  684.         clr     tr1             ;stop watchdog
  685. gotit:  jnb     Adat,gotit
  686.         ret
  687.  
  688. timer1int:
  689.         djnz    r1,t3           ;we wait for 143 ms.
  690.         mov     r1,#2           
  691.         setb    Charbad         ;flag to resend the character
  692.         clr     Adat            ;1 on the data line
  693.         mov     b,#8
  694. tt1:    djnz    b,tt1           ;wait for it
  695.         clr     Aclk            ;clock asserted
  696.         mov     b,#8            ;sync up the controller to the
  697. tt2:    djnz    b,tt2           ;amiga
  698.         setb    Aclk
  699.         mov     b,#10
  700. tt3:    djnz    b,tt3
  701.         setb    Adat
  702. t3:     reti                    ;return and send again.
  703.  
  704. ATtb1: 
  705.         .db     0               
  706.         .db     58h             ;F9
  707.         .db     0               
  708.         .db     54h             ;F5
  709.         .db     52h             ;F3
  710.         .db     50h             ;F1
  711.         .db     51h             ;F2
  712.         .db     5bh             ;F12=right parenthesis
  713.         .db     0
  714.         .db     59h             ;F10
  715.         .db     57h             ;F8
  716.         .db     55h             ;F6
  717.         .db     53h             ;F4
  718.         .db     42h             ;TAB
  719.         .db     00h             ;~
  720.         .db     0
  721.  
  722.         .db     0
  723.         .db     64h             ;Left ALT
  724.         .db     60h             ;Left SHIFT
  725.         .db     0
  726.         .db     66h             ;Left Ctrl=Left AMIGA
  727.         .db     10h             ;Q
  728.         .db     01h             ;1
  729.         .db     0
  730.         .db     0
  731.         .db     0
  732.         .db     31h             ;Z
  733.         .db     21h             ;S
  734.         .db     20h             ;A
  735.         .db     11h             ;W
  736.         .db     02h             ;2
  737.         .db     0
  738.  
  739.         .db     0
  740.         .db     33h             ;C
  741.         .db     32h             ;X
  742.         .db     22h             ;D
  743.         .db     12h             ;E
  744.         .db     04h             ;4
  745.         .db     03h             ;3
  746.         .db     0
  747.         .db     0
  748.         .db     40h             ;SPACE
  749.         .db     34h             ;V
  750.         .db     23h             ;F
  751.         .db     14h             ;T
  752.         .db     13h             ;R
  753.         .db     05h             ;5
  754.         .db     0
  755.  
  756.         .db     0
  757.         .db     36h             ;N
  758.         .db     35h             ;B
  759.         .db     25h             ;H
  760.         .db     24h             ;G
  761.         .db     15h             ;Y
  762.         .db     06h             ;6
  763.         .db     0
  764.         .db     0
  765.         .db     0
  766.         .db     37h             ;M
  767.         .db     26h             ;J
  768.         .db     16h             ;U
  769.         .db     07h             ;7
  770.         .db     08h             ;8
  771.         .db     0
  772.  
  773.         .db     0
  774.         .db     38h             ;<
  775.         .db     27h             ;K
  776.         .db     17h             ;I
  777.         .db     18h             ;O
  778.         .db     0Ah             ;0
  779.         .db     09h             ;9
  780.         .db     0
  781.         .db     0
  782.         .db     39h             ;>
  783.         .db     3ah             ;/
  784.         .db     28h             ;L
  785.         .db     29h             ; ';'
  786.         .db     19h             ;P
  787.         .db     0bh             ;-
  788.         .db     0
  789.  
  790.         .db     0
  791.         .db     0
  792.         .db     2ah             ;'
  793.         .db     0
  794.         .db     1ah             ;[
  795.         .db     0ch             ;=
  796.         .db     0
  797.         .db     0
  798.         .db     62h             ;CAPS LOCK?
  799.         .db     61h             ;Right SHIFT
  800.         .db     44h             ;RETURN
  801.         .db     1bh             ;]
  802.         .db     0
  803.         .db     0dh             ;\
  804.         .db     0
  805.         .db     0
  806.  
  807.         .rs     6
  808.         .db     41h             ;Back SPACE
  809.         .db     0
  810.         .db     0
  811.         .db     1dh             ;1 keypad
  812.         .db     0
  813.         .db     2dh             ;4 keypad
  814.         .db     3dh             ;7 keypad
  815.         .db     0
  816.         .db     0
  817.         .db     0
  818.  
  819.         .db     0fh             ;0 keypad
  820.         .db     3ch             ;dot keypad
  821.         .db     1eh             ;2 keypad
  822.         .db     2eh             ;5 keypad
  823.         .db     2fh             ;6 keypad
  824.         .db     3eh             ;8 keypad
  825.         .db     45h             ;ESCAPE!
  826.         .db     63h             ;Number Lock=CTRL
  827.         .db     5ah             ;F11=( keypad
  828.         .db     5eh             ;+ keypad
  829.         .db     1fh             ;3 keypad
  830.         .db     4ah             ;- keypad
  831.         .db     5dh             ;* keypad
  832.         .db     3fh             ;9 keypad
  833.         .db     67h             ;scroll Lock=Right AMIGA
  834.         .db     0
  835. ATtb2:
  836.         .rs     3
  837.         .db     56h             ;F7
  838.         .db     66h             ;print screen=Left Amiga
  839.         .rs     11
  840.  
  841.         .db     0
  842.         .db     65h             ;Right ALT
  843.         .db     0
  844.         .db     0
  845.         .db     67h             ;Right CTL=RIGHT AMIGA
  846.         .rs     11
  847.  
  848.         .rs     10h
  849.         
  850.         .rs     10h
  851.  
  852.         .rs     10
  853.         .db     5ch             ;/key, supposedly
  854.         .rs     5
  855.  
  856.         .rs     10
  857.         .db     43h             ;Numeric Enter
  858.         .rs     5
  859.  
  860.         .rs     9
  861.         .db     1ch             ;End=Mouse down
  862.         .db     0
  863.         .db     4fh             ;Cursor Left
  864.         .db     0eh             ;Home=Mouse up
  865.         .db     0
  866.         .db     0
  867.         .db     63h             ;MACRO key=control
  868.  
  869.         .db     2ch             ;Insert=Mouse Left
  870.         .db     46h             ;Delete
  871.         .db     4dh             ;Cursor Down
  872.         .db     0
  873.         .db     4eh             ;Cursor Right
  874.         .db     4ch             ;Cursor Up
  875.         .rs     4
  876.         .db     5fh             ;Page Down=Help
  877.         .db     0
  878.         .db     66h             ;print screen=LEFT AMIGA
  879.         .db     47h             ;Page up=mouse right
  880.         .db     40h             ;Break=Space?
  881.         .db     0
  882. XTtb1:
  883.         .db     0
  884.         .db     45h             ;esc
  885.         .db     01h             ;1
  886.         .db     02h             ;2
  887.         .db     03h             ;3
  888.         .db     04h             ;4
  889.         .db     05h             ;5
  890.         .db     06h             ;6
  891.         .db     07h             ;7
  892.         .db     08h             ;8
  893.         .db     09h             ;9
  894.         .db     0ah             ;0
  895.         .db     0bh             ;-
  896.         .db     0ch             ;=
  897.         .db     41h             ;Backspace
  898.         .db     42h             ;Tab
  899.  
  900.         .db     10h             ;Q
  901.         .db     11h             ;W
  902.         .db     12h             ;E
  903.         .db     13h             ;R
  904.         .db     14h             ;T
  905.         .db     15h             ;Y
  906.         .db     16h             ;U
  907.         .db     17h             ;I
  908.         .db     18h             ;O
  909.         .db     19h             ;P
  910.         .db     1Ah             ;[
  911.         .db     1Bh             ;]
  912.         .db     44h             ;ENTER
  913.         .db     66h             ;L.CTL=LEFT AMIGA
  914.         .db     20h             ;A
  915.         .db     21h             ;S
  916.  
  917.         .db     22h             ;D
  918.         .db     23h             ;F
  919.         .db     24h             ;G
  920.         .db     25h             ;H
  921.         .db     26h             ;J
  922.         .db     27h             ;K
  923.         .db     28h             ;L
  924.         .db     29h             ;';'
  925.         .db     2Ah             ;'
  926.         .db     00h             ;~
  927.         .db     60h             ;Left Shift
  928.         .db     0dh             ;\
  929.         .db     31h             ;Z
  930.         .db     32h             ;X
  931.         .db     33h             ;C
  932.         .db     34h             ;V
  933.  
  934.         .db     35h             ;B
  935.         .db     36h             ;N
  936.         .db     37h             ;M
  937.         .db     38h             ;<
  938.         .db     39h             ;>
  939.         .db     3Ah             ;/
  940.         .db     61h             ;Right Shift
  941.         .db     5dh             ;Numeric *
  942.         .db     64h             ;Left Alt
  943.         .db     40h             ;space
  944.         .db     62h             ;CapsLock
  945.         .db     50h             ;F1
  946.         .db     51h             ;F2
  947.         .db     52h             ;F3
  948.         .db     53h             ;F4
  949.         .db     54h             ;F5
  950.  
  951.         .db     55h             ;F6
  952.         .db     56h             ;F7
  953.         .db     57h             ;F8
  954.         .db     58h             ;F9
  955.         .db     59h             ;F10
  956.         .db     63h             ;Number Lock=Control
  957.         .db     67h             ;Scroll Lock=Right Amiga
  958.         .db     3dh             ;Numeric 7
  959.         .db     3eh             ;* 8
  960.         .db     3fh             ;* 9
  961.         .db     4ah             ;* -
  962.         .db     2dh             ;* 4
  963.         .db     2eh             ;* 5
  964.         .db     2fh             ;* 6
  965.         .db     5eh             ;* +
  966.         .db     1dh             ;* 1
  967.  
  968.         .db     1eh             ;* 2
  969.         .db     1fh             ;* 3
  970.         .db     0fh             ;* 0
  971.         .db     3ch             ;* .
  972.         .db     63h             ;print screen=CONTROL
  973.         .db     0
  974.         .db     0
  975.         .db     5ah             ;F11=Numeric (
  976.         .db     5bh             ;F12=Numeric )
  977.         .rs     7
  978.  
  979.         .rs     10h
  980.  
  981.         .rs     10h
  982. XTtb2:
  983.         .rs     10h
  984.  
  985.         .rs     12
  986.         .db     43h             ;Numeric Enter
  987.         .db     67h             ;Right Control=RIGHT AMIGA
  988.         .rs     2
  989.  
  990.         .rs     10h
  991.         
  992.         .rs     5
  993.         .db     5ch             ;Numeric /key
  994.         .db     0
  995.         .db     66h             ;Print Screeen=Left Amiga
  996.         .db     65h             ;Right Alt
  997.         .rs     7
  998.  
  999.         .rs     6
  1000.         .db     5fh             ;BREAK=HELP!
  1001.         .db     0eh             ;Home=MOUSE UP
  1002.         .db     4ch             ;cursor up
  1003.         .db     47h             ;pageup=mouse right
  1004.         .db     0
  1005.         .db     4fh             ;cursor left
  1006.         .db     0
  1007.         .db     4eh             ;cursor right
  1008.         .db     0
  1009.         .db     1ch             ;End=mouse down
  1010.  
  1011.         .db     4dh             ;cursor down
  1012.         .db     5fh             ;page down=HELP!
  1013.         .db     2ch             ;insert=mouse left
  1014.         .db     46h             ;delete
  1015.         .rs     12
  1016.        
  1017.         .rs     15
  1018.         .db     63h             ;Macro=control
  1019.  
  1020.         .rs     10h
  1021.  
  1022.         .end    0
  1023.  
  1024.